//
//  HMAD.m
//  HMAD
//
//  Created by hm on 2017/8/11.
//  Copyright © 2017年 hm. All rights reserved.
//

@interface HMAD()

@end

@implementation HMAD

static HMAD *g_HMAD = NULL;

+ (HMAD *)sharedManager {
    if (!g_HMAD) {
        g_HMAD = [[HMAD alloc] init];
    }
    return g_HMAD;
}

- (instancetype)regWithAppId:(NSString*)appId secretKey:(NSString *)secretKey {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
//        [g_HMAD openThirdAd];
        [[HMSetting sharedManager] requestSettingsWithAppId:appId secretKey:secretKey];
    });
    return g_HMAD;
}

- (void)openThirdAd {
    NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [documents[0] stringByAppendingPathComponent:@"settings.plist"];
    //加载本地
    NSData * storeData = [NSData dataWithContentsOfFile:path];
    if (storeData != nil) {
        //json
        NSDictionary *settings = [NSJSONSerialization JSONObjectWithData:storeData options:kNilOptions error:nil];
        if (settings != nil) {
            NSDictionary *partner = settings[@"partner"];
            if ([NSNull null] == (id) partner) {
                return;
            }
            if (partner!=nil){
                NSNumber *enable = partner[@"cta"];
                if ([enable isEqualToNumber: @1]) {
//                   [CTAnalysisService analysisWithSlot_id:CTAdsID];
                }
            }
        }
    }
}

+ (instancetype)getHMAd {
    return g_HMAD;
}

+ (NSString*)getSDKVersion{
    return SDKVersion;
}

+(void)cleanCache {
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
}

@end
